<%--
    Document   : email
    Created on : Nov 13, 2010, 12:27:01 PM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.mail.*,
        java.util.Properties,
        org.ilookinto.util.CloseUtil,
        javax.mail.internet.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<%
    String folderName = request.getParameter("folder");
    if (folderName == null || folderName.isEmpty()) {

      return;
    }

    Properties props = new Properties();
    // props.put("mail.from", "user2@mailserver.com");
    javax.mail.Session emailSession = javax.mail.Session.getInstance(props);
    final Store store = emailSession.getStore("imap");
    store.connect("localhost", "elookinto", "elookinto");
    try {
      Folder[] fs = store.getDefaultFolder().list();
      for (Folder f: fs)
        out.println(f.getFullName());
      final Folder folder = store.getDefaultFolder().getFolder("INBOX").getFolder(folderName);
    for (Folder f: store.getDefaultFolder().getFolder("INBOX").list())
        out.println(f.getFullName()+"pppp");
      folder.delete(true);
     // store.close();
      out.println("delete1");
    } catch (Exception e) {
      e.printStackTrace();
      out.println(e.getMessage());
    }
    try {
      final Folder folder = store.getFolder(folderName);

      folder.delete(true);
      //store.close();
      out.println("delete2");
    } catch (Exception e) {
      e.printStackTrace();
      out.println(e.getMessage());
    }
    store.close();
%>

